<?php
/**
 *
 *
 * @package Admin
 */

if ( !defined( 'BIGCKOOL_VERSION' ) ) {
	header( 'HTTP/1.0 403 Forbidden' );
	die;
}
global $bigckool_admin;


 function create_bigckool_setting_page()
    {
    
    	// Add screen icon
    	
        // Set class property
        
        
bigckool_setting_page_init();
        ?>
        <div class="wrap">
            <?php echo get_screen_icon(); ?>
            <h2>BIGC KOOL SETTING</h2>          
            <?php 
            	if(isset($_GET['settings-updated']) && $_GET['settings-updated']=='true'):
            ?>
            <div id="setting-error-settings_updated" class="updated settings-error"> 
<p><strong>Settings saved.</strong></p></div>
            <?php
            endif;
            ?> 
            <form method="post" action="options.php">
            <?php
                // This prints out all hidden setting fields
                settings_fields( 'bigckool_option_group' );   
                do_settings_sections( 'bigckool_setting' );
                submit_button(); 
            ?>
            </form>
        </div>
        <?php
        
    }

  
     function bigckool_setting_page_init()
    {        
        add_settings_section(
            'setting_section_id', // ID
            'Facebook APP Setting', // Title
              'print_section_info' , // Callback
            'bigckool_setting' // Page
        );  

        add_settings_field(
            'app_id', // ID
            'APP ID', // Title 
              'app_id_callback' , // Callback
            'bigckool_setting', // Page
            'setting_section_id' // Section           
        );      

        add_settings_field(
            'app_secret', 
            'APP Secret', 
             'app_secret_callback' , 
            'bigckool_setting', 
            'setting_section_id'
        ); 
        add_settings_field(
            'app_url', 
            'APP URL', 
             'app_url_callback' , 
            'bigckool_setting', 
            'setting_section_id'
        );   
        add_settings_field(
            'fanpage_url', 
            'FanPage URL', 
             'fanpage_url_callback' , 
            'bigckool_setting', 
            'setting_section_id'
        );    

        add_settings_field(
            'fanpage_id', 
            'FanPage ID', 
             'fanpage_id_callback' , 
            'bigckool_setting', 
            'setting_section_id'
        );  
        
        add_settings_field(
            'like_enable', 
            'Cho phép bình chọn', 
             'like_enable_callback' , 
            'bigckool_setting', 
            'setting_section_id'
        );  
    }

    /**
     * Sanitize each setting field as needed
     *
     * @param array $input Contains all settings fields as array keys
     */
     function sanitize( $input )
    {
    	
        $new_input = array();
        if( isset( $input['app_id'] ) )
            $new_input['app_id'] = absint( $input['app_id'] );

        if( isset( $input['app_secret'] ) )
            $new_input['app_secret'] = sanitize_text_field( $input['app_secret'] );

        return $new_input;
    }

    /** 
     * Print the Section text
     */
     function print_section_info()
    {
        print 'Enter your settings below:';
    }

    /** 
     * Get the settings option array and print one of its values
     */
     function app_id_callback()
    {$options = get_option( 'bigckool_option_fb' );
        printf(
            '<input type="text" id="app_id" name="bigckool_option_fb[app_id]" value="%s" />',
            isset( $options['app_id'] ) ? esc_attr( $options['app_id']) : ''
        );
    }

    /** 
     * Get the settings option array and print one of its values
     */
     function app_secret_callback()
    {$options = get_option( 'bigckool_option_fb' );
        printf(
            '<input style="width: 500px;" type="text" id="app_secret" name="bigckool_option_fb[app_secret]" value="%s" />',
            isset( $options['app_secret'] ) ? esc_attr( $options['app_secret']) : ''
        );
    }
    function app_url_callback()
    {$options = get_option( 'bigckool_option_fb' );
        printf(
            '<input style="width: 500px;" type="text" id="app_url" name="bigckool_option_fb[app_url]" value="%s" />',
            isset( $options['app_url'] ) ? esc_attr( $options['app_url']) : ''
        );
    }
     function fanpage_url_callback()
    {$options = get_option( 'bigckool_option_fb' );
        printf(
            '<input style="width: 500px;" type="text" id="fanpage_url" name="bigckool_option_fb[fanpage_url]" value="%s" />',
            isset( $options['fanpage_url'] ) ? esc_attr( $options['fanpage_url']) : ''
        );
    }
    
    function fanpage_id_callback()
    {$options = get_option( 'bigckool_option_fb' );
        printf(
            '<input type="text" id="fanpage_id" name="bigckool_option_fb[fanpage_id]" value="%s" />',
            isset( $options['fanpage_id'] ) ? esc_attr( $options['fanpage_id']) : ''
        );
    }
    
    function like_enable_callback()
    {$options = get_option( 'bigckool_option_fb' );
    //t($options['like_enable']);
        printf(
            '<input type="checkbox" id="like_enable" name="bigckool_option_fb[like_enable]" value="1" %s/>',
            ( $options['like_enable']==1 ) ? 'checked="checked"': ''
        );
    }

    create_bigckool_setting_page();